package dk.pun.dums.client;

import java.util.Date;

import com.google.gwt.user.client.Cookies;

public final class AnonymousLogin {

	private static final String COOKIE_NAME = "ANONLOGIN";
	private static final int LOGIN_EXPIRATION = 3600000;
	
	public static void login() {
		final Date date = new Date(System.currentTimeMillis() + LOGIN_EXPIRATION);
		Cookies.setCookie(COOKIE_NAME, Boolean.TRUE.toString(), date);
	}
	
	public static void logout() {
		Cookies.removeCookie(COOKIE_NAME);
	}
	
	public static boolean isLoggedIn() {
		boolean loggedIn;
		final String cookieValue = Cookies.getCookie(COOKIE_NAME);
		if (cookieValue != null && Boolean.valueOf(cookieValue)) {
			loggedIn = true;
		} else {
			loggedIn = false;
		}
		return loggedIn;
	}
	
	private AnonymousLogin() {
	}
}
